package com.example.springvalidationdemo.controller;

import com.example.springvalidationdemo.domain.Student;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/test")
    public Student test(@RequestBody @Validated Student student) {
        return student;
    }

    // @Validated 注解可以赋值 value 属性进行分组，value 是可以以数组的形式赋值，既可以分配多个组
    @PostMapping("/students")
    public Student create(@RequestBody @Validated(Student.Create.class) Student student) {
        return student;
    }

    @PutMapping("/students")
    public Student update(@RequestBody @Validated(Student.Update.class) Student student) {
        return student;
    }
}
